<script setup>
import { ref, provide } from "vue";
import { onLaunch } from "@dcloudio/uni-app";

import { USER_DATA_INJECTION_KEY } from "./constants/index";
import { login } from "./api";

// 用户信息
const userData = ref(null);
const updateUserData = (data) => {
  userData.value = data;
};
provide(USER_DATA_INJECTION_KEY, {
  userData,
  updateUserData,
});

// 应用初始化调用一次
onLaunch(() => {
  // #ifdef MP-WEIXIN
  // 获取code
  uni.login({
    onlyAuthorize: true,
    async success({ code }) {
      const res = await login('wechat', { code });
      console.log("login:", res, code);
    },
  });
  // #endif
});
</script>

<style lang="scss">
@import "nutui-uniapp/styles/index.scss";
@import "./styles/main.scss";
@import './styles/common.scss';
</style>
